<?php

namespace app\common\model;

use think\Model;


class MerchantCashCalc extends Model
{

    

    

    // 表名
    protected $name = 'merchant_cash_calc';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'date_type_text',
        'reg_time_text',
        'last_time_text',
        'next_time_text',
        'status_text'
    ];
    

    
    public function getDateTypeList()
    {
        return ['1' => __('Date_type 1'), '2' => __('Date_type 2')];
    }

    public function getStatusList()
    {
        return ['1' => __('Status 1'), '2' => __('Status 2')];
    }


    public function getDateTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['date_type']) ? $data['date_type'] : '');
        $list = $this->getDateTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getRegTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['reg_time']) ? $data['reg_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getLastTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['last_time']) ? $data['last_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getNextTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['next_time']) ? $data['next_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    protected function setRegTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setLastTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setNextTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


}
